#include "notepad.h"

Notepad::Notepad(QWidget *parent) : QMainWindow(parent)
{
    initWindow();
}

void Notepad::initWindow()
{
    QMainWindow window;
    m_bar = menuBar();
    filemenu = m_bar->addMenu("文件");
    editmenu = m_bar->addMenu("编辑");
    seemenu = m_bar->addMenu("查看");

    //QAction *openact = filemenu->addAction("打开文件");
    //connect(openact, &QAction::triggered, this, &Calculator::)
    //openact->setShortcut(QKeySequence("Ctrl+N"));
    //QMenu *dirmenu = filemenu->addMenu("二级菜单");
    //dirmenu->addAction("")
    //filemenu->addAction("新建标签页");
    QAction *newbiaoqian = filemenu->addAction("新建标签页");
    newbiaoqian->setShortcut(QKeySequence("Ctrl+N"));
    //filemenu->addAction("新建窗口");
    QAction *newwin = filemenu->addAction("新建窗口");
    newwin->setShortcut(QKeySequence("Ctrl+Shift+N"));
    QAction *open = filemenu->addAction("打开");
    open->setShortcut(QKeySequence("Ctrl+O"));
    QAction *save = filemenu->addAction("保存");
    save->setShortcut(QKeySequence("Ctrl+S"));
    QAction *othersave = filemenu->addAction("另存为");
    othersave->setShortcut(QKeySequence("Ctrl+Shift+S"));
    QAction *allsave = filemenu->addAction("全部保存");
    allsave->setShortcut(QKeySequence("Ctrl+S"));
    QAction *setpage = filemenu->addAction("页面设置");
    QAction *printpage = filemenu->addAction("打印");
    printpage->setShortcut(QKeySequence("Ctrl+P"));
    QAction *closechoice = filemenu->addAction("关闭选项卡");
    closechoice->setShortcut(QKeySequence("Ctrl+W"));
    QAction *closewin = filemenu->addAction("关闭窗口");
    closewin->setShortcut(QKeySequence("Ctrl+Shift+W"));
    QAction *exit = filemenu->addAction("退出");
    //editmenu->addAction("撤销");
    QAction *undo = editmenu->addAction("撤销");
    undo->setShortcut(QKeySequence("Ctrl+z"));
    edit = new QTextEdit;
    setCentralWidget(edit);
    connect(undo,&QAction::triggered, this, &Notepad::unundo);

    editmenu->addAction("剪切");
    editmenu->addAction("复制");
    editmenu->addAction("粘贴");
    editmenu->addAction("删除");
    editmenu->addAction("使用必应搜索");
    editmenu->addAction("查找");
    editmenu->addAction("查找下一个");
    editmenu->addAction("查找上一个");
    editmenu->addAction("替换");
    editmenu->addAction("转到");
    editmenu->addAction("全选");
    QAction *dtime = editmenu->addAction("时间/日期");
    editmenu->addAction("字体");

    QMenu *ssonmenu = seemenu->addMenu("缩放");
    ssonmenu->addAction("放大");
    ssonmenu->addAction("缩小");
    ssonmenu->addAction("还原默认缩放");

    seemenu->addAction("状态栏");
    seemenu->addAction("自动换行");

    //QCheckBox *ch1 = new QCheckBox(seemenu->addAction("状态栏"));
    //    QAction *undo = editmenu->addAction("撤销");
    //    undo->setShortcut(QKeySequence("Ctrl+z"));
    //    edit = new QTextEdit;
    //    connect(undo,&QAction::triggered, this, &Calculator::unundo);

    //获取时间  QTime
    QString tm = QTime::currentTime().toString("hh:mm:ss");
    edit->append(tm);
    //获取日期  QDate
    edit->append(QDate::currentDate().toString("yyyy-MM-dd"));

    connect(dtime,&QAction::triggered,[=](){
        //获取时间日期 QDateTime
        edit->append(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
    });

    timeLabel = new QLabel;
    s_Bar = statusBar();
    timeLabel->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
    //    s_Bar->showMessage(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
    s_Bar->addWidget(timeLabel);
    //QTimer定时器 QTime
    timer = new QTimer(this);

    connect(timer,&QTimer::timeout,[=](){
        //        s_Bar->showMessage(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
        timeLabel->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
    });

    connect(dtime,&QAction::triggered,[=](){
        lcd = new QLCDNumber;
        lcd->setDigitCount(8);
        connect(timer,&QTimer::timeout,[=](){
            lcd->display(QDateTime::currentDateTime().toString("hh:mm:ss"));
        });
        lcd->show();
    });
    timer->start(100);
}

void Notepad::unundo()
{
    edit->undo();
}
\
